package day14;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class ChatClient {
    public static void main(String[] args) {
        Socket s=null;
        try {
             s=new Socket("127.0.0.1",9999);
            InputStream in = s.getInputStream();
            OutputStream out = s.getOutputStream();
            PrintWriter pw=new PrintWriter(out,true);
            BufferedReader br=new BufferedReader(new InputStreamReader(in));
            Scanner sc=new Scanner(System.in);
            while (true){
                System.out.print("聊：");
                String ques=sc.next();
                pw.println(ques);
                //pw.flush();
                String huifu=br.readLine();
                System.out.println("服务器回复："+huifu);
                if(ques.equals("exit"))
                    break;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(s!=null) {
                try {
                    s.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
